local skel = fk.CreateSkill {
  name = "rmt__heli",
  tags = {Skill.Combo},
}

Fk:loadTranslationTable{
  ["rmt__heli"] = "鹤唳",
  [":rmt__heli"] = "连招技（牌+牌+牌，点数须递增），此牌不可响应，上述每有一张♣牌，你弃置其中一名目标角色一张牌。",

  ["@rmt__heli"] = "鹤唳",
  ["#rmt__heli-choose"] = "鹤唳：弃置其中一名目标角色一张牌",
  ["#rmt__heli-discard"] = "鹤唳：弃置 %dest 一张牌",

  ["$rmt__heli1"] = "辽名可止啼，鹤唳可却氐！",
  ["$rmt__heli2"] = "风展旗，鹤鸣镝，群贼披靡！",
}


skel:addEffect(fk.CardUsing, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and
      data.extra_data and data.extra_data.combo_skill and data.extra_data.combo_skill[skel.name]
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@rmt__heli", 0)
    data.disresponsiveList = table.simpleClone(room.players)
    local targets, n = {}, 0
    room.logic:getEventsByRule(GameEvent.UseCard, 3, function (e)
      local use = e.data
      if use.from == player then
        if use.tos and #use.tos > 0 then
          table.insertTableIfNeed(targets, use.tos)
        end
        if use.card.suit == Card.Club then
          n = n + 1
        end
        return true
      end
    end, 1)
    if #targets == 0 or n == 0 then return end
    for i = 1, n do
      if player.dead then return end
      targets = table.filter(targets, function (to)
        return table.find(to:getCardIds("he"), function (id)
          return not player:prohibitDiscard(id)
        end)
      end)
      if #targets == 0 then return end
      local to = room:askToChoosePlayers(player, {
        min_num = 1, max_num = 2, targets = targets, skill_name = skel.name, cancelable = false,
        prompt = "#rmt__heli-choose",
      })[1]
      local prompt = "#rmt__heli-discard::"..to.id
      if to == player then
        room:askToDiscard(player, {min_num = 1, max_num = 1, include_equip = true, cancelable = false, skill_name = skel.name, prompt = prompt})
      else
        local card = room:askToChooseCard(player, {target = to, flag = "he", skill_name = skel.name, prompt = prompt})
        room:throwCard(card, skel.name, to, player)
      end
    end
  end,
})

skel:addEffect(fk.AfterCardUseDeclared, {
  can_refresh = function (self, event, target, player, data)
    return target == player and player:hasSkill(skel.name, true)
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if data.card.number > 0 and data.card.number < 14 then
      room:addTableMark(player, "@rmt__heli", data.card.number)
    else
      room:setPlayerMark(player, "@rmt__heli", 0)
      return
    end
    if #player:getTableMark("@rmt__heli") == 3 then
      local yes = true
      local number = 14
      local events = room.logic:getEventsByRule(GameEvent.UseCard, 3, function (e)
        local use = e.data
        if use.from == player then
          if use.card.number > 0 and use.card.number < 14 then
            if use.card.number >= number then
              yes = false
            else
              number = use.card.number
            end
          else
            yes = false
          end
          return true
        end
      end, 1)
      if #events < 3 then
        yes = false
      end
      if yes then
        data.extra_data = data.extra_data or {}
        data.extra_data.combo_skill = data.extra_data.combo_skill or {}
        data.extra_data.combo_skill[skel.name] = true
        return
      end
    end
    local mark, number = {}, 14
    room.logic:getEventsByRule(GameEvent.UseCard, 2, function (e)
      local use = e.data
      if use.from == player then
        if use.card.number > 0 and use.card.number < number then
          table.insert(mark, 1, use.card.number)
          number = use.card.number
        end
        return true
      end
    end, 1)
    room:setPlayerMark(player, "@rmt__heli", mark)
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  player.room:setPlayerMark(player, "@rmt__heli", 0)
end)


return skel
